//
//  ObjectDetailParser.m
//  EasyBuy
//
//  Created by Zhu Xiangjun on 10/17/12.
//  Copyright (c) 2012 shen donghao. All rights reserved.
//

#import "ObjectDetailParser.h"

@implementation ObjectDetailParser

//@synthesize userData;
//@synthesize imageArray;
//@synthesize objectId;
//@synthesize price;
//@synthesize officalprice;
//@synthesize freight;
//@synthesize depreciation;
//@synthesize tradetype;
//@synthesize title;
//@synthesize time;
//@synthesize distance;
//@synthesize description;

-(NSArray *)excuteToObjects:(NSDictionary *)itemFeeds{
    
    NSMutableArray *feedsArray = [[NSMutableArray alloc] init];
    NSDictionary *item = [itemFeeds objectForKey:@"thing"];

    ObjectDetailData *detailData = [[ObjectDetailData alloc] init];
    detailData.userData     = [[UserData alloc] init];
    detailData.imageArray   = [[NSMutableArray alloc] init];
    detailData.objectId     = [[item objectForKey:@"id"] intValue];
    detailData.price        = [[item objectForKey:@"price"] intValue];
    detailData.officalprice = [[item objectForKey:@"officalprice"] intValue];
    detailData.freight      = [[item objectForKey:@"freight"] intValue];
    detailData.depreciation = [[item objectForKey:@"depreciation"] intValue];
    detailData.tradetype    = [[item objectForKey:@"tradetype"] intValue];
    detailData.title        = [item objectForKey:@"title"];
    detailData.time         = [item objectForKey:@"time"];
    detailData.distance     = [item objectForKey:@"distance"];
    detailData.description  = [item objectForKey:@"description"];
    
    NSDictionary *userDic = [item objectForKey:@"user"];
    detailData.userData.userid = [[userDic objectForKey:@"userid"] intValue];
    detailData.userData.usertype = [[userDic objectForKey:@"usertype"] intValue];
    detailData.userData.username = [userDic objectForKey:@"username"];
    detailData.userData.usericon = [userDic objectForKey:@"usericon"];
    
    NSArray *imagesArray = [item objectForKey:@"images"];
    int count = [imagesArray count];
    
    for ( int i = 0 ; i < count ; i++){
        NSDictionary *imageDic = [imagesArray objectAtIndex:i];
        [detailData.imageArray addObject:[imageDic objectForKey:@"image"]];
    }
    
    [feedsArray addObject:detailData];
    
    [detailData release];
    
    return feedsArray;
}

@end
